package com.anjie.powerproject.strategy.utils;

import java.math.RoundingMode;
import java.text.DecimalFormat;

public class DecimalFormatUtils {

    public static Double lower(Double dicimal, String format) {
        DecimalFormat df = new DecimalFormat(format);
        df.setRoundingMode(RoundingMode.FLOOR);
        return Double.parseDouble(df.format(dicimal));
    }

    public static Double upper(Double dicimal, String format) {
        DecimalFormat df = new DecimalFormat(format);
        df.setRoundingMode(RoundingMode.UP);
        return Double.parseDouble(df.format(dicimal));
    }

    public static Double round(Double dicimal, String format) {
        DecimalFormat df = new DecimalFormat(format);
        df.setRoundingMode(RoundingMode.HALF_UP);
        return Double.parseDouble(df.format(dicimal));
    }

    public static void main(String[] args) {
        System.out.println(DecimalFormatUtils.round(0.45328, "0.0"));
    }
}